package com.smartao.base.selectitem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartao.base.Constant;
import com.smartao.base.init.InitializeServiceOrder;
import com.smartao.base.module.Module;
import com.smartao.base.module.ModuleService;
import com.smartao.base.selecttype.Selecttype;
import com.smartao.base.selecttype.SelecttypeService;
import com.smartao.core.init.AbstractDataInitializeService;

@Service
public class SelectitemInitializeService extends AbstractDataInitializeService{

	@Autowired
	private SelectitemService selectitemService;
	
	@Autowired
	private SelecttypeService selecttypeService;
	
	@Autowired
	private ModuleService moduleService;
	
	@Override
	public int getOrder() {
		return InitializeServiceOrder.INIT_ORDER_SELECTITEM;
	}

	@Override
	public void initData() throws Exception {
		
		Selectitem item = selectitemService.findByCode(Constant.SELECTITEM_DEPARTMENT_DIMENTION_ADMIN);
		if(item!=null){
			return;
		}
		
		Module module = moduleService.findByModuleKey(Constant.MODULE_BASE);
		
		// 添加组织维度
		Selecttype selecttype = selecttypeService.findByCode(Constant.SELECTTYPE_DEPARTMENT_DIMENSION);
		Selectitem selectitem = new Selectitem();
		selectitem.setName("行政维度");
		selectitem.setCode(Constant.SELECTITEM_DEPARTMENT_DIMENTION_ADMIN);
		selectitem.setSelecttype(selecttype);
		selectitem.setModule(module);
		selectitemService.save(selectitem);
		
		Selectitem item1 = new Selectitem();
		item1.setName("工会维度");
		item1.setCode("DEPARTMENT_DIMENTION_TRADEUNION");
		item1.setSelecttype(selecttype);
		item1.setModule(module);
		selectitemService.save(item1);
		
		// 添加岗位级别
		Selecttype s2 = selecttypeService.findByCode(Constant.SELECTTYPE_POSITION_RANK);
		Selectitem item2 = new Selectitem();
		item2.setName("岗位级别 - 总监");
		item2.setCode(Constant.SELECTITEM_POSITION_RANK_DIRECTOR);
		item2.setSelecttype(s2);
		item2.setModule(module);
		selectitemService.save(item2);
		
		Selectitem item3 = new Selectitem();
		item3.setName("岗位级别 - 经理");
		item3.setCode(Constant.SELECTITEM_POSITION_RANK_MANAGER);
		item3.setSelecttype(s2);
		item3.setModule(module);
		selectitemService.save(item3);
		
		// 添加角色类型
		Selecttype s3 = selecttypeService.findByCode(Constant.SELECTTYPE_ROLE_TYPE);
		Selectitem item4 = new Selectitem();
		item4.setName("系统角色");
		item4.setCode(Constant.SELECTITEM_ROLE_TYPE_SYSTEM);
		item4.setSelecttype(s3);
		selectitemService.save(item4);
	}

}
